Crate atomic_immut

Source
Expand description

Atomic immutable value.

§Examples

use std::sync::Arc;
use std::thread;
use atomic_immut::AtomicImmut;

let v = Arc::new(AtomicImmut::new(vec![0]));
{
    let v = v.clone();
    thread::spawn(move || {
                      let mut new = (&*v.load()).clone(); // Loads the immutable reference
                      new.push(1);
                      v.store(new); // Replaces the existing value
                  });
}
while v.load().len() == 1 {}
assert_eq!(&*v.load(), &vec![0, 1]);

Structs§